package com.testMain.filetest;

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.FileTime;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author 贾明祯
 * @ClassName TestFile
 * @Date 2020/10/21 19:09
 * @Introduce
 */
public class TestFile {
    public static void main(String[] args) throws IOException {
//        /** 读取文件  */
//        File dir = new File("D:/wwwwwww.txt");
//        FileInputStream fileInputStream = new FileInputStream(dir);
//        BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
//
//        /** 创建文件 */
//        File file = new File("D:/dd.txt");
//        file.createNewFile();
//        FileOutputStream fileOutputStream = new FileOutputStream(file);
//        BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
//        byte[] readBytes = new byte[1024];
//        int bytes = 0;
//
//        /** 写入内容 */
//        while ((bytes=bufferedInputStream.read(readBytes))!=-1){
//            bufferedOutputStream.write(readBytes,0,bytes);
//        }
//
//        /** 读取文件并转码输出 */
//        InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream("D:/scpt纯净版.dmp"),"UTF-8");
//        BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
//        String str = null;
//        while ((str = bufferedReader.readLine())!=null){
//            System.out.println(str);
//        }
//        bufferedReader.close();
//        bufferedInputStream.close();
//        bufferedOutputStream.close();
        FileTime t= Files.readAttributes(Paths.get("D:/wwwwwww.txt"), BasicFileAttributes.class).creationTime();
        System.out.println(t);
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time =  dateFormat.format(t);
        System.out.println(time);
//        System.out.println(FileCreateDate("D:/wwwwwww.txt"));

    }
    public  static String  FileCreateDate(String str) {
        String strTime = null;
        try {
            Process process = Runtime.getRuntime().exec("cmd /C dir " + str + "/tc");
            InputStream inputStream = process.getInputStream();
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
            String line = null;
            while ((line = bufferedReader.readLine()) != null){
                if(line.endsWith(".txt")){
                    strTime= line.substring(0,17);
                    break;
                }

            }
        }catch (Exception e){
            e.printStackTrace();
        }

        return strTime;
    }
}
